package com.uplooking.controller;

import com.alibaba.fastjson.JSON;
import com.uplooking.domain.AriticalManageBean;
import com.uplooking.domain.ResponseBean;
import com.uplooking.service.QueryArticalManage;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class AriticalManageController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer page = Integer.valueOf(req.getParameter("page"));
        Integer counts = Integer.valueOf(req.getParameter("limit"));
        resp.setContentType("application/json;charset=utf-8");
        QueryArticalManage queryArticalManage = new QueryArticalManage();
        List<AriticalManageBean> articleAll = queryArticalManage.getArticleAll(page, counts);
        ResponseBean responseBean = new ResponseBean();
//        //这些是固定写法
        responseBean.setCode(0);
        //set一个字串  空的也可以
        responseBean.setMsg("myms");
        //这个是设置最大数据条数
        responseBean.setCount(100);
        responseBean.setData(articleAll);

        String result = JSON.toJSONString(responseBean);
        System.out.println(result);
        resp.getWriter().write(result);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
